package com.ttdevs.testmediaplayer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class PlayerActivity extends Activity {

	private boolean isPlayer = false;
	private Button start;
	private Button stop;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		start = (Button) findViewById(R.id.start);
		stop = (Button) findViewById(R.id.stop);
		start.setOnClickListener(onClickListener);
		stop.setOnClickListener(onClickListener);

	}

	OnClickListener onClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {

			switch (v.getId()) {
			case R.id.start:
				if (!isPlayer) {
					isPlayer = true;
					startService(new Intent(PlayerActivity.this,
							MediaPlayerService.class));
				}
				break;
			case R.id.stop:
				if (isPlayer) {
					isPlayer = false;
					stopService(new Intent(PlayerActivity.this,
							MediaPlayerService.class));
				}
				break;

			default:
				break;
			}
		}
	};
}